import React, { Component } from 'react'
import { Form, Input, Button} from 'antd';
import request from '../util/request'

const layout = {
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },
  };
  const tailLayout = {
    wrapperCol: { offset: 8, span: 16 },
  };

export default class Registry extends Component {
    render() {
        const onFinish = values => {
            request.post('/api/registry',values).then(res => {
                if(res.code === 1){
                    alert("注册成功");
                    this.props.history.push('/login');
                }else{
                    alert("注册失败")
                }
            })
        };
        
        const onFinishFailed = errorInfo => {
            console.log('Failed:', errorInfo);
        };
        
        return (
            <Form
                {...layout}
                name="basic"
                initialValues={{ remember: true }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                >
                <Form.Item
                    label="姓名"
                    name="username"
                    rules={[{ required: true, message: 'Please input your username!' }]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="密码"
                    name="password"
                    rules={[{ required: true, message: 'Please input your password!',min:4,max:6 }]}
                >
                    <Input.Password />
                </Form.Item>

                <Form.Item
                    label="学号"
                    name="num"
                    rules={[{ required: true, message: 'Please input your password!' }]}
                >
                    <Input/>
                </Form.Item>

                <Form.Item {...tailLayout}>
                    <Button type="primary" htmlType="submit">
                        注册
                    </Button>
                </Form.Item>
            </Form>
        )
    }
}
